<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Login</title>
    <%= stylesheet_link_tag "../javascripts/ext/resources/css/ext-all.css" %>
    <%= stylesheet_link_tag "/stylesheets/blue.css" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/prototype.js" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/scriptaculous.js" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/effects.js" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/ext-prototype-adapter.js" %>
    <%if session[:explorer_info]=="IE" %>
      <%= javascript_include_tag "/javascripts/ext/adapter/ext/ext-base.js" %>
    <%end %>
    <%= javascript_include_tag "/javascripts/ext/ext-all-debug.js" %>
    <%= javascript_include_tag "/javascripts/ext/build/locale/ext-lang-zh_CN.js" %>
  </head>
  <body>
    <script>
        Ext.onReady(function(){
            
            Ext.QuickTips.init();
                
            // turn on validation errors beside the field globally
            Ext.form.Field.prototype.msgTarget = 'side';
                
            var bd = Ext.getBody();
            var loginForm = new Ext.FormPanel({
                //labelAlign: 'top',
                labelWidth: 75, // label settings here cascade unless overridden
                url: '/index/login',
                frame: true,
                title: '系统登录',
                bodyStyle: 'padding:5px 5px 0',
                width: 350,
                defaults: {
                    width: 230
                },
                defaultType: 'textfield',
                    
                items: [{
                        fieldLabel: '用户名',
                        name: 'user_name',
                        allowBlank: false
                    }, {
                        fieldLabel: '密码',
                        name: 'password',
                        inputType: 'password',
                        allowBlank: false
                    }],
                    
                buttons: [{
                        text: '提交',
                        handler: onItemClick
                    }, {
                        text: '取消',
                        handler: onItemClick
                    }]
            });
            function onItemClick(item){
                if (item.text == "提交") {
                    if (loginForm.form.isValid()) {
                        Ext.Ajax.request({
                            url: '/admin/getAllPolicy?start=0&limit=10',
                            params: loginForm.form.getValues(true),
                            method: 'GET',
                            success: function(result, request){
                                Ext.MessageBox.alert('消息', result.responseText);
                            },
                            failure: function(result, request){
                                Ext.MessageBox.alert('消息', '登录过程中和服务器的通信失败!');
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('输入验证有错', '请输入必输选项');
                    }
                }
                else if (item.text == "来电显示") {
                    window.document.location.href = "/customers/customersByPhoneNo?phone_number=13853225231";
                }
                //Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
            }
            loginForm.render(document.body);
            loginForm.getEl().center();
        });
    </script>
  </body>
</html>
